/**
 * 
 */
var tpl = require('./index.html');
var style = require('./index.css');

module.exports = function(mod, name) {
	mod.directive(name, ['$window',function($window) {
		return {
			restrict: 'EA',
			replace: true,
			transclde: true,
			scope: {
			},
			template: tpl,
			link: function(scope, element, attrs) {
				var $element = $(element).find('#pagination');
				scope.$parent.$watch('totalCounts',function(){
					if(scope.$parent.totalCounts){
						$element.jqPaginator({
							totalCounts: parseInt(scope.$parent.totalCounts),
							pageSize: parseInt(scope.$parent.pageSize),
							currentPage: parseInt(scope.$parent.pageno),
							onPageChange: function(num,type){
								var url = scope.$parent.url;
								url = url.replace('pageno',num);
								if(url != decodeURIComponent($window.location.hash)){
									$window.location.href = url;	
								}
							}
						});
					}
				});
			}
		}
	}]);
}
	
